import request from 'umi-request';

export async function getUserList(params) {
  return request('/api/member/api-member/roleAssignment/queryUserList', {
    method: 'post',
    data: {
      name: params.name,
      pageNum: params.current,
      pageSize: params.pageSize,
    },
    requestType: 'form'
  }).then((res) => {
    const data = res.data;
    if (res.flag) {
      return {
        current: data.currPage,
        data: data.list,
        pageSize: data.pageSize,
        success: true,
        total: data.totalCount,
      };
    } else {
      return {};
    }
  });
}

export async function getRolePageList(params) {
  return request('/api/member/api-member/roleAssignment/queryRoleList', {
    method: 'post',
    data: {
      roleName: params.roleName,
      pageNum: params.current,
      pageSize: params.pageSize,
    },
    requestType: 'form'
  }).then((res) => {
    const data = res.data;
    if (res.flag) {
      return {
        current: data.currPage,
        data: data.list,
        pageSize: data.pageSize,
        success: true,
        total: data.totalCount,
      };
    } else {
      return {};
    }
  });
}


export async function getOrgGroupPageList(params) {
  return request('/api/member/api-member/roleAssignment/queryOrgGroupList', {
    method: 'post',
    data: {
      groupName: params.groupName,
      pageNum: params.current,
      pageSize: params.pageSize,
    },
    requestType: 'form'
  }).then((res) => {
    const data = res.data;
    if (res.flag) {
      return {
        current: data.currPage,
        data: data.list,
        pageSize: data.pageSize,
        success: true,
        total: data.totalCount,
      };
    } else {
      return {};
    }
  });
}

export async function getUserMsgRoles(userId) {
  return request(`/api/member/api-member/noticeRole/getNoticeRoleByUser?userId=${userId}`, {
    method: 'get',
  }).then((res) => {
    if (res.flag){
      return res.data;
    }else {
      return [];
    }
  });
}

export async function getMsgRolesList() {
  return request(`/api/member/api-member/noticeRole/getNoticeRoleListNoPage`, {
    method: 'get',
  }).then((res) => {
    if (res.flag){
      return res.data;
    }else {
      return [];
    }
  });
}

export async function getUserRoles(userId) {
  return request(`/api/member/api-member/roleAssignment/getUserRoleInterface`, {
    method: 'post',
    data: {userId: userId},
    requestType: 'form'
  }).then((res) => {
    if (res.flag){
      return res.data;
    }else {
      return [];
    }
  });
}

export async function getRolesList() {
  return request(`/api/member/api-member/roleAssignment/queryRoleEntityListInterface`, {
    method: 'get',
  }).then((res) => {
    if (res.flag){
      return res.data;
    }else {
      return [];
    }
  });
}

export async function updateUserRole(params) {
  return request(`/api/member/api-member/roleAssignment/updateUserRoleInterface`, {
    method: 'post',
    data: params,
  }).then((res) => {
    return res;
  });
}

export async function updateUserMsgRole(params) {
  return request(`/api/member/api-member/noticeRole/saveOrUpdateNoticeUserRole`, {
    method: 'post',
    data: params,
    requestType: 'form'
  }).then((res) => {
    return res;
  });
}

export async function addRoleInterface(params) {
  return request(`/api/member/api-member/roleAssignment/saveRoleInterface`, {
    method: 'post',
    data: params,
  }).then((res) => {
    return res;
  });
}

export async function deleteUserRole(roleId) {
  return request(`/api/member/api-member/roleAssignment/dateleRoleInterface?roleId=${roleId}`, {
    method: 'delete',
  }).then((res) => {
    return res;
  });
}

export async function getMenuEntityList(type) {
  return request(`/api/member/api-member/roleAssignment/queryMenuEntityListInterface?type=${type}`, {
    method: 'get',
  }).then((res) => {
    if (res.flag){
      return res.data;
    }else {
      return [];
    }
  });
}

export async function getRoleMenu(roleId,type) {
  return request(`/api/member/api-member/roleAssignment/getRoleMenuInterface?roleId=${roleId}&type=${type}`, {
    method: 'get',
  }).then((res) => {
    if (res.flag){
      return res.data;
    }else {
      return [];
    }
  });
}

export async function updateRoleMenu(params) {
  return request(`/api/member/api-member/roleAssignment/updateRoleMenuInterface`, {
    method: 'post',
    data: params,
  }).then((res) => {
    return res;
  });
}

export async function updateRoleFunc(params) {
  return request(`/api/member/api-member/roleAssignment/updateRoleAuthorityInterface`, {
    method: 'post',
    data: params,
  }).then((res) => {
    return res;
  });
}


export async function getOrgGroupList() {
  return request(`/api/member/api-member/roleAssignment/queryOrgGroupListInterface`, {
    method: 'get',
  }).then((res) => {
    if (res.flag){
      return res.data;
    }else {
      return [];
    }
  });
}

export async function getOrgGroupById(groupId) {
  return request(`/api/member/api-member/roleAssignment/getOrgGroupInterface`, {
    method: 'post',
    data: groupId,
  }).then((res) => {
    if (res.flag){
      return res.data;
    }else {
      return {};
    }
  });
}

export async function getUserGroupList(userId) {
  return request(`/api/member/api-member/roleAssignment/getUserGroupListInterface?userId=${userId}`, {
    method: 'get',
  }).then((res) => {
    if (res.flag){
      return res.data;
    }else {
      return [];
    }
  });
}

export async function addUserGroup(params) {
  return request(`/api/member/api-member/roleAssignment/saveOrgGroupInterface`, {
    method: 'post',
    data: params,
  }).then((res) => {
    return res;
  });
}

export async function updateUserGroup(params) {
  return request(`/api/member/api-member/roleAssignment/updateUserGroupInterface`, {
    method: 'post',
    data: params,
  }).then((res) => {
    return res;
  });
}

export async function updateOrgGroup(params) {
  return request(`/api/member/api-member/roleAssignment/updateOrgGroupInterface`, {
    method: 'post',
    data: params,
  }).then((res) => {
    return res;
  });
}

export async function deleteOrgGroup(groupId) {
  return request(`/api/member/api-member/roleAssignment/deleteOrgGroupInterface?groupId=${groupId}`, {
    method: 'delete',
  }).then((res) => {
    return res;
  });
}

export async function addMenuInterface(params) {
  return request(`/api/member/api-member/roleAssignment/saveMenuInterface`, {
    method: 'post',
    data: params,
  }).then((res) => {
    return res;
  });
}

export async function updateMenuInterface(params) {
  return request(`/api/member/api-member/roleAssignment/updateMenuInterface`, {
    method: 'post',
    data: params,
  }).then((res) => {
    return res;
  });
}

export async function deleteMenu(menuId) {
  return request(`/api/member/api-member/roleAssignment/deleteMenuInterface?menuId=${menuId}`, {
    method: 'delete',
  }).then((res) => {
    return res;
  });
}







